import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;

public class MulticastReceiver {
	public static void main(String[] args) {
		
		try {
			InetAddress group = InetAddress.getByName("228.0.0.1");
			int port = 4000;
			try(MulticastSocket ms = new MulticastSocket(port)){
				ms.joinGroup(group);
				byte[] buffer = new byte[1024];
				while(true) {
					DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
					ms.receive(dp); 	
					System.out.println(new String(dp.getData(), 0, dp.getLength()));
				}
			}
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}